package com.demo.user;

import com.demo.common.model.User;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.SqlPara;

import java.util.List;

public class UserService {
    private User dao = new User().dao();
    public boolean login(User user){
        Kv kv = Kv.by("username",user.getUsername()).set("password",user.getPassword());
        SqlPara sqlPara = Db.getSqlPara("user.login",kv);
        return dao.find(sqlPara).size()>0;
    }

    public List<User> list(){
        return dao.findAll();
    }

    public boolean addUser(User user){
        return user.save();
    }

    public boolean delUser(User user){
        return user.delete();
    }
}
